Tryit Editor v2.3

Edit This Code:
<!DOCTYPE html> <html> <head> <style> table, th { border: 1px solid black; } </style> </head> <body> <table border="1"> <tr> <th>Cell 1</th> <th>Cell 2</th> <th>Cell 3</th> <th>Cell 4</th> </tr> </table> <p>Click the button to return the position of each cell in the table row.</p> <button onclick="myFunction()">Try it</button> <p id="demo"></p> <script> function myFunction() { var x = document.getElementsByTagName("th"); var txt = ""; var i; for (i = 0; i < x.length; i++) { txt = txt + "The index of Cell "+(i+1)+" is: "+x[i].cellIndex+"<br>"; } document.getElementById("demo").innerHTML = txt; } </script> </body> <!-- Mirrored from www.w3schools.com/jsref/tryit.asp?filename=tryjsref_th_cellindex2 by HTTrack Website Copier/3.x [XR&CO'2014], Fri, 23 Jan 2015 08:35:11 GMT --> </html>
Result:
Try it Yourself - © w3schools.com